﻿using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using eCommMongo.Core;
using eCommMongo.Core.Domain.Posts;
using eCommMongo.Service.Pictures;

namespace eCommMongo.Web.Mapper
{
    public class PostMapper
    {

        //public static StatusModel ToPostModel(Post status)
        //{
        //    var _pictureService = EngineContext.Current.Resolve<IPictureService>();

        //    var m = new StatusModel()
        //        {
        //            Point = status.Point,
        //            Id = status.Id,
        //            IsProduct = status.IsProductStatus,
        //            Pics = ToStatusPictureModel(status.StatusPictures),
        //            Text = status.Text,
        //            ProductStatusInfo = ToProductStatusInfo(status.Product),
        //            CommentModels = ToCommentModel(status.Comments),
        //            PosterLogoUrl = status.Customer.CustomerLogoId.HasValue

        //                    ? _pictureService.GetPictureUrl(status.Customer.CustomerLogo.PictureId, GetCustomerLogoSize(), false)
        //                    : _pictureService.GetDefaultPictureUrl(GetCustomerLogoSize())
        //        };
        //    return m;
        //}

        //public static IList<CommentModel> ToCommentModel(ICollection<Comment> comments)
        //{
            
        //    if (comments == null)
        //    {
        //        return null;
        //    }
        //    else
        //    {
        //        return comments.Select(c => ToCommentModel(c)).ToList();
        //    }
        //}

        //public static CommentModel ToCommentModel(Comment comment, string statusId)
        //{
        //    var _pictureService = EngineContext.Current.Resolve<IPictureService>();
        //    var _statusService = EngineContext.Current.Resolve<IStatusService>();
        //    var status = _statusService.GetStatusById(statusId, false);

        //    return new CommentModel()
        //        {
        //            IsMyComment = comment.Commenter.Id == status.Customer.Id, 
        //            Text = comment.Text,
        //            StatusId = status.Id.ToString(),
        //            CommenterId = comment.Commenter.Id.ToString(),
        //            CreatedAt = comment.CreatedAt,
        //            CustomerLogUrl =
        //                comment.Commenter.CustomerLogo.Picture !=null
        //                    ? _pictureService.GetPictureUrl(comment.Commenter.CustomerLogo.Picture, GetCustomerLogoSize(), false)
        //                    : _pictureService.GetDefaultPictureUrl(GetCustomerLogoSize()),
        //        };
        //}

        //public static IList<StatusListItemModel> PrepareStatusListItemModel(IEnumerable<Status> statuses)
        //{

        //    if (statuses == null)
        //    {
        //        return new List<StatusListItemModel>();
        //    }
        //    else
        //    {
        //        return statuses.Select(c =>ToStatusListItemModel(c)).ToList();
        //    }
        //}

        //public static IPagedList<StatusListItemModel> ToPagedStatusListItemModels(IPagedList<Status> statuses)
        //{
        //    if (statuses == null)
        //    {
        //        return null;
        //    }
        //    else
        //    {
        //        var tempList  = statuses.Select(c => ToStatusListItemModel(c)).ToList();

        //        var result = new PagedList<StatusListItemModel>(tempList, statuses.PageIndex, statuses.PageSize, statuses.TotalCount);
        //        return result;
        //    }
        //}

        //private static int GetCustomerLogoSize()
        //{
        //    return int.Parse(ConfigurationManager.AppSettings["CustomerLogoSize"]);
        //}
        //public static StatusListItemModel ToStatusListItemModel(Status status )
        //{

        //    var _pictureService = EngineContext.Current.Resolve<IPictureService>();

        //    return new StatusListItemModel()
        //        {
        //            Id = status.Id,
        //            CreatedAt = status.CreatedAt,
        //            Text = KeepLinkOutPut.ToHtmlString(status.Text),
        //            CustomerId = status.CustomerId,
        //            Deleted = status.Deleted,
        //            CustomerLogoUrl = status.Customer.CustomerLogoId.HasValue ? _pictureService.GetPictureUrl(status.Customer.CustomerLogo.PictureId, GetCustomerLogoSize(), false) : _pictureService.GetDefaultPictureUrl(GetCustomerLogoSize()),
        //            CustomerEmail = status.Customer.Email,
        //            CustomerName = status.Customer.Username,
        //            StatusPictures = ToStatusPictureModel(status.StatusPictures),
        //            IsProductStatus = status.IsProductStatus,
        //            ProductStatus = ToProductStatus(status.Product),
        //            StatusTags = ToStatusTags(status.StatusTags),
        //        };
        //}

        //private static IList<StatusTagModel> ToStatusTags(ICollection<StatusTag> statusTags)
        //{
        //    if (statusTags == null)
        //        return null;
        //    else
        //    {
        //        return statusTags.Select(c => new StatusTagModel()
        //            {
        //                TagName = c.Tag.TagName,
        //                TagValue = c.Tag.TagValue
        //            }).ToList();
        //    }
        //}

        //private static ProductStatus ToProductStatus(Product product)
        //{
        //    if (product == null)
        //    {
        //        return null;
        //    }
        //    else
        //    {
        //        return new ProductStatus()
        //            {
        //                ProductId = product.Id,
        //                ProductPrice = product.ProductVariants.First().Price,
        //                ProductStock = product.ProductVariants.First().StockQuantity,
        //            };
        //    }
        //}

        //private static ProductStatusInfo ToProductStatusInfo(Product product)
        //{
        //    if (product == null)
        //    {
        //        return null;
        //    }
        //    else
        //    {
        //        return new ProductStatusInfo()
        //        {
        //            ProductId = product.Id,
        //            PvInfos = ToProductVariantInfo(product)
        //        };
        //    }
        //}

        //private static IList<ProductVariantInfo> ToProductVariantInfo(Product product)
        //{
        //    var result = product.ProductVariants.Select(c => new ProductVariantInfo()
        //        {
        //            ProductStock = c.StockQuantity,
        //            ProductPrice = c.Price,
        //            ProductVariantId = c.Id
        //        }).ToList();
        //    return result;
        //}


        //private static IList<StatusPictureModel> ToStatusPictureModel(ICollection<StatusPicture> statusPictures)
        //{
        //    var _pictureService = EngineContext.Current.Resolve<IPictureService>();

        //    if (statusPictures == null)
        //    {
        //        return null;
        //    }
        //    else
        //    {
        //        return statusPictures.Select(c => new StatusPictureModel()
        //            {
        //                PicId = c.PictureId,
        //                PicUrl = _pictureService.GetPictureUrl(c.PictureId, 80, false),

        //            }).ToList();
        //    }
        //}

     


        //public static IList<TagIntroStatusModel> ToTagIntroStatusModels(ICollection<TagIntroStatuses> statuseses )
        //{
        //    if (statuseses == null)
        //    {
        //        return null;
        //    }
        //    else
        //    {
        //        var result = statuseses.Select(c => new TagIntroStatusModel()
        //            {
        //                CreatedAt = c.CreatedAt,
        //                CustomerId = c.CustomerId,
        //                IsProductStatus = c.IsProductStatus,
        //                Point = c.Point,
        //                ProductId = c.ProductId,
        //                Text = c.Text
        //            }).ToList();
        //        return result;
        //    }
          
        //}

        //public static IPagedList<TagIntroListItemModel> ToPagedTagStatusesList(IPagedList<TagIntroStatuses> tagIntros)
        //{
        //    if (tagIntros == null)
        //    {
        //        return null;
        //    }
        //    else
        //    {
        //        var tempList = tagIntros.Select(c => new TagIntroListItemModel()
        //        {
        //            TagId = c..Id,
        //            TagName = c.Tag.TagName,
        //            TagValue = c.Tag.TagValue,
        //            CountTaged = c.Tag.CountTaged,

        //        }).ToList();

        //        var result = new PagedList<TagIntroListItemModel>(tempList, tagIntros.PageIndex, tagIntros.PageSize, tagIntros.TotalCount);
        //        return result;
        //    }
        //}
    }
}